/*
 * @(#)CommonCodeBOImpl.java $version 2013-3-1
 * 
 * Copyright 2013 NADO Group. All rights Reserved.
 * NADO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nado.iims2.community.bo.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nado.extensions.util.DataMap;
import com.nado.iims2.community.bo.CommonCodeBO;
import com.nado.iims2.community.dao.CommonCodeDAO;
import com.nado.iims2.community.model.CategoryModel;
import com.nado.iims2.community.model.CodeModel;

/**
 * The Class CommonCodeBOImpl.
 * 
 * @author nado
 */
@Service("CommonCodeBO")
public class CommonCodeBOImpl implements CommonCodeBO {
	/** The log. */
	private static Log log = LogFactory.getLog(CommonCodeBOImpl.class);
	
	/**
	 * The common code dao.
	 */
	@Autowired
	private CommonCodeDAO commonCodeDAO = null;
	
	@Override
	public List<DataMap> getCommonCategoryList() {
		try {
			List<DataMap> resultList = new ArrayList<DataMap>();
			resultList = commonCodeDAO.selectCommonCategoryList();
			return resultList;
		} catch (Exception e) {
			log.error(e, e);
			return new ArrayList<DataMap>();
		}
	}

	@Override
	public int getCommonCategoryListCount() {
		try {
			return commonCodeDAO.selectCommonCategoryListCount();
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
	}

	@Override
	public CategoryModel getCommonCategoryDetail(String categoryCd) {
		try {
			CategoryModel result = new CategoryModel();
			result = commonCodeDAO.selectCommonCategoryDetail(categoryCd);
			return result;
		} catch (Exception e) {
			log.error(e, e);
			return null;
		}
	}

	@Override
	public List<DataMap> getCommonCodeList(String categoryCd) {
		try {
			List<DataMap> resultList = new ArrayList<DataMap>();
			resultList = commonCodeDAO.selectCommonCodeList(categoryCd);
			return resultList;
		} catch (Exception e) {
			log.error(e, e);
			return new ArrayList<DataMap>();
		}
	}

	@Override
	public int getCommonCodeListCount(String categoryCd) {
		try {
			return commonCodeDAO.selectCommonCodeListCount(categoryCd);
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
	}

	@Override
	public CodeModel getCommonCodeDetail(String categoryCd, String commonCd) {
		try {
			CodeModel result = new CodeModel();
			result = commonCodeDAO.selectCommonCodeDetail(categoryCd, commonCd);
			return result;
		} catch (Exception e) {
			log.error(e, e);
			return null;
		}
	}

	@Override
	public int writeCommonCategory(CategoryModel model) {
		int result = 0;
		try {
			result = commonCodeDAO.updateCommonCategory(model);
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
		return result;
	}

	@Override
	public int removeCommonCategory(String categoryCd) {
		int result = 0;
		try {
			result = commonCodeDAO.deleteCommonCategory(categoryCd);
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
		return result;
	}

	@Override
	public int writeCommonCode(CodeModel model) {
		int result = 0;
		try {
			result = commonCodeDAO.updateCommonCode(model);
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
		return result;
	}

	@Override
	public int removeCommonCode(String categoryCd, String commonCd) {
		int result = 0;
		try {
			result = commonCodeDAO.deleteCommonCode(categoryCd, commonCd);
		} catch (Exception e) {
			log.error(e, e);
			return 0;
		}
		return result;
	}

	@Override
	public List<DataMap> getCommonCodeAndNameList(String categoryCd) {
		try {
			List<DataMap> result = new ArrayList<DataMap>();
			result = commonCodeDAO.selectCommonCodeAndNameList(categoryCd);
			return result;
		} catch (Exception e) {
			log.error(e, e);
			return new ArrayList<DataMap>();
		}
	}

}
